#include "junix.h"

int main(int argc, char **argv)
{
	int fd = inotify_init();
	if( fd== -1)
		err_sys("inotify_init");

	printf("fd:%d\n", fd);

	if( inotify_add_watch(fd, ".", IN_ACCESS) == -1)
		err_sys("inotify_add_watch");

/*
	struct inotify_event {
		int      wd;       // Watch descriptor
		uint32_t mask;     // Mask of events 
		uint32_t cookie;   // Unique cookie associating related
	                       // events (for rename(2))
		uint32_t len;      // Size of name field
		char     name[];   // Optional null-terminated name
	};
*/

	struct inotify_event ie;
	//memset(&ie, 0, sizeof(ie) );
	ssize_t len;
	while(1)
	{
		if( (len=read(fd, (char*)&ie, sizeof(ie) ))==-1)
			err_sys("read");

		printf("file read:%s\n",ie.name);
	}

    exit(0);
}

